package com.huaqin.obeacons.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharedPreferenceUtil {
	private final static String USER_DATA_PREF = "user_data_pref";
	private final static String APP_DATA_PREF = "obeacons_data_pref";

	public static void storeUserInfo(Context context, String name,
			String account, String imei) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				USER_DATA_PREF, Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("name", name);
		editor.putString("account", account);
		editor.putString("imei", imei);
		editor.commit();
	}

	public static boolean accountIsEmpty(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				USER_DATA_PREF, Context.MODE_PRIVATE);
		if (sharedPreferences.getString("account", null) == null) {
			return true;
		} else {
			return false;
		}
	}

	public static String getName(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				USER_DATA_PREF, Context.MODE_PRIVATE);
		return sharedPreferences.getString("name", null);
	}

	public static String getAccount(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				USER_DATA_PREF, Context.MODE_PRIVATE);
		return sharedPreferences.getString("account", null);
	}

	public static String getImei(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				USER_DATA_PREF, Context.MODE_PRIVATE);
		return sharedPreferences.getString("imei", null);
	}

	public static void setAppVoiceEnable(Context context, boolean isChecked) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				APP_DATA_PREF, Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("shared_key_sound", isChecked);
		editor.commit();
	}

	public static void setAppVibrateEnable(Context context, boolean isChecked) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				APP_DATA_PREF, Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("shared_key_vibrate", isChecked);
		editor.commit();
	}

	public static boolean getAppVoiceEnable(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				APP_DATA_PREF, Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("shared_key_sound", true);
	}

	public static boolean getAppVibrateEnable(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				APP_DATA_PREF, Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("shared_key_vibrate", true);
	}
	
	public static void setFirstStartFlag(Context context, boolean isChecked) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				APP_DATA_PREF, Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("shared_first_flag", isChecked);
		editor.commit();
	}
	public static boolean getFirstStartFlag(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				APP_DATA_PREF, Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("shared_first_flag", false);
	}
	
}
